package com.cg.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;
import java.util.Map;

@Mapper
public interface InterviewMapper {

    @Select("SELECT i.id AS interview_id, i.interviewer_type AS interviewer_type_code, i.session_title AS interviewer_type, i.create_time, i.update_time FROM interview_session i WHERE i.user_id = #{userId} ORDER BY i.create_time DESC")
    List<Map<String, Object>> listByUser(@Param("userId") Long userId);

    @Insert("INSERT INTO interview_session (user_id, session_title, interviewer_type, topics, classic_count, project_count, status, create_time, update_time) VALUES (#{userId}, #{interviewerTypeDesc}, #{interviewerType}, #{questionTypes}, #{questionCount}, 2, 'active', NOW(), NOW())")
    int insertInterview(@Param("userId") Long userId,
                        @Param("interviewerType") Integer interviewerType,
                        @Param("interviewerTypeDesc") String interviewerTypeDesc,
                        @Param("targetPosition") String targetPosition,
                        @Param("questionTypes") String questionTypes,
                        @Param("questionCount") Integer questionCount);

    @Delete("DELETE FROM interview_session WHERE id = #{id} AND user_id = #{userId}")
    int deleteByIdAndUser(@Param("id") Long id, @Param("userId") Long userId);

    @Select("SELECT LAST_INSERT_ID()")
    Long lastInsertId();

    @Update("UPDATE interview_session SET status = #{status}, update_time = NOW() WHERE id = #{id} AND user_id = #{userId}")
    int updateEvaluation(@Param("id") Long id,
                         @Param("userId") Long userId,
                         @Param("evaluation") String evaluation,
                         @Param("suggestions") String suggestions,
                         @Param("totalScore") Integer totalScore,
                         @Param("status") Integer status);
}


